package com.job.controller;

import com.job.pojo.Java;
import com.job.process.MyProcessor;
import com.job.utils.MyUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class DisplayController {
    //从第0页开始每页显示15条
    private final MyUtils myUtils =new MyUtils(0,15);
    //首次显示
    @GetMapping(value = {"/index.html","/"})
    public String display(HttpSession session) {
        //当工作时间为空或者不同时才更新
        if (session.getAttribute("jobTime")==null||(!session.getAttribute("jobTime").equals(MyProcessor.jobTime))){
            session.setAttribute("jobTime", MyProcessor.jobTime);
        }
        return "index";
    }
    //翻页
    @GetMapping("/page/{page}")
    @ResponseBody
    public List<Java> adjustPage(@PathVariable("page") String page){
        return myUtils.simplePage(page);
    }
    //通过id删
    @GetMapping(value="/delcur/{id}")
    public String delete(@PathVariable("id") long id){
        MyUtils.javaJpa.deleteById(id);
        myUtils.setDel(true);
        return "redirect:/";
    }
}
